package com.boc.langxiang.presenter.index;


import com.boc.langxiang.contract.index.ArticleDetailWordsContract;
import com.boc.langxiang.entity.request.ArticleFeedbackRequest;
import com.boc.langxiang.entity.response.ArticleShareDetailContent;
import com.boc.langxiang.entity.response.BaseResponse;
import com.boc.langxiang.net.ApiService;
import com.boc.langxiang.net.HandleErrorSubscriber;
import com.boc.langxiang.net.NetClient;

import rx.Observable;
import rx.android.schedulers.AndroidSchedulers;
import rx.schedulers.Schedulers;

/**
 * CreateTime: 2016-06-14上午10:40
 * Author: wjkjinke00@126.com
 * Description:
 */
public class ArticleDetailWordsPresenter implements ArticleDetailWordsContract.Presenter {

    private final ApiService mService;
    private ArticleDetailWordsContract.View mView;

    public ArticleDetailWordsPresenter(ArticleDetailWordsContract.View view) {
        mService = NetClient.getInstance().net().create(ApiService.class);
        mView = view;
    }


    @Override
    public void articlefeedback(String id, String content) {
        mView.showLoading();
        ArticleFeedbackRequest request = new ArticleFeedbackRequest();
        request.aid = id;
        request.content = content;
        Observable<BaseResponse> register = mService.articlefeedback(request.params());
        register.subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .unsubscribeOn(Schedulers.io())
                .subscribe(new HandleErrorSubscriber<BaseResponse>(mView) {
                    @Override
                    public void onSuccess(BaseResponse response) {
                        mView.articleFeedbackSuccess();
                    }
                });
    }

    @Override
    public void shareClick(String aid) {
//        mView.showLoading();
        mService.shareClick(aid + "")
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .unsubscribeOn(Schedulers.io())
                .subscribe(new HandleErrorSubscriber<BaseResponse<ArticleShareDetailContent>>(mView) {
                    @Override
                    public void onSuccess(BaseResponse<ArticleShareDetailContent> response) {
                        ArticleShareDetailContent content = response.getContent();
                        if (content != null) {
                            ArticleShareDetailContent.RowBean row = content.getRow();
                            mView.getShareDataSuccess(row);
                        }
                    }
                });
    }
}
